﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using Dapper;
using PMS.IRepository;
using PMS.Models.Base;
using PMS.Utils;

namespace PMS.Repository
{
    public class Group_PowerRepository : BaseRepository<Group_Power>, IGroup_PowerRepository
    {
        #region 公共方法


        public int Add(Group_Power user)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Group_Power(");
            strSql.Append("PowerId,GroupId,CreateBy,CreateDate,ModifyBy,ModifyDate)");
            strSql.Append(" values (");
            strSql.Append("@PowerId,@GroupId,@CreateBy,@CreateDate,@ModifyBy,@ModifyDate)");
            strSql.Append(";select @@IDENTITY");
            using (DbConn)
            {
                return DbConn.Execute(strSql.ToString(), user);
            }
        }

        public int Edit(Group_Power user)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Group_Power set ");
            strSql.Append("CreateBy=@CreateBy,");
            strSql.Append("CreateDate=@CreateDate,");
            strSql.Append("ModifyBy=@ModifyBy,");
            strSql.Append("ModifyDate=@ModifyDate");
            strSql.Append(" where PowerId=@PowerId and GroupId=@GroupId ");
            using (DbConn)
            {
                return DbConn.Execute(strSql.ToString(), user);
            }
        }

        public Group_Power Dtl(int id)
        {
            throw new NotImplementedException();
        }

        public Group_Power Dtl(int groupId, int powerId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Select *  from Group_Power ");
            strSql.Append(" where PowerId=@PowerId and GroupId=@GroupId ");
            using (DbConn)
            {
                return DbConn.QueryFirstOrDefault<Group_Power>(strSql.ToString(), new { PowerId = powerId, GroupId = groupId });
            }
        }

        public bool IsExists(int groupId)
        {
            throw new NotImplementedException();
        }


        public int Delete(int id, string deleteBy)
        {
            throw new NotImplementedException();
        }

        public int Delete(int[] ids, string deleteBy)
        {
            throw new NotImplementedException();
        }

        public List<Group_Power> GetList()
        {
            string strSql = "Select * from Group_Power";
            using (DbConn)
            {
                return DbConn.Query<Group_Power>(strSql).ToList();
            }
        }

        public List<Group_Power> GetList(Hashtable ht)
        {
            throw new NotImplementedException();
        }

        public int GetCount(Hashtable ht)
        {
            throw new NotImplementedException();
        }

        public void GetStrWhereAndParam(Hashtable ht, StringBuilder sb, Dictionary<string, object> param)
        {
            throw new NotImplementedException();
        }

        #endregion

    }
}